package com.maomao.maomaochong_i.adapterPackage;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by maomao on 2017/5/17.
 * 4.21还不能实现自动播放
 */

public class TuLuenBoAdaper extends PagerAdapter {
    private List<ImageView> viewList;

    public TuLuenBoAdaper(List<ImageView> viewList) {
        this.viewList=viewList;
    }

    /**
     * 获得当前页卡的数量
     */
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    /**
     * 判断视图是否由对象产生
     */
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0==arg1;
    }

    /**
     * 实例化页卡
     */
    public Object instantiateItem(ViewGroup container, int position) {
        position %= viewList.size();
        if(position < 0){
            position = viewList.size() + position;
        }
        ImageView view = viewList.get(position);
        ViewPager vp = (ViewPager) view.getParent();
        if(vp != null){
            ViewGroup parent = (ViewGroup)vp;
            parent.removeView(view);
        }
        container.addView(view);
        return view;
    }

    /**
     * 删除页卡
     */
    public void destroyItem(ViewGroup container, int position, Object object) {
//        container.removeView(viewList.get(position % viewList.size()));
    }
}
